export default {html: `<h1><a id="1__0"></a>1. 方法的定义与调用：</h1>
<blockquote>
<p>权限访问修饰符   [静态的]    返回的类型    方法名字( 参数列表 ) {</p>
<p>​		// 方法体</p>
<p>​		// 有返回类型时， return  值</p>
<p>}</p>
</blockquote>
<h2><a id="11__10"></a>1.1 方法的调用</h2>
<ul>
<li>静态方法调用： <code>类名.方法名(参数值)</code></li>
<li>非静态方法调用：  <code>obj.方法名(参数值)</code></li>
</ul>
<h2><a id="12__15"></a>1.2 方法参数值传递</h2>
<ul>
<li>基本类型+String  ：  传递的是值的副本</li>
<li>引用类型             ：  传递的是 地址的 副本</li>
</ul>
<pre><div class="hljs"><code class="lang-java"><span class="hljs-keyword">package</span> lesson02;
<span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">TestMain2</span> {
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">main</span><span class="hljs-params">(String[] args)</span> {
        <span class="hljs-type">int</span> <span class="hljs-variable">a</span> <span class="hljs-operator">=</span> <span class="hljs-number">10</span>;
        TestMain2.abc(a);
        System.out.println(a); <span class="hljs-comment">// 10</span>

        <span class="hljs-type">A</span> <span class="hljs-variable">a1</span>  <span class="hljs-operator">=</span><span class="hljs-keyword">new</span> <span class="hljs-title class_">A</span>();
        a1.a = <span class="hljs-number">10</span>;
        TestMain2.changeA(a1);
        System.out.println(a1.a); <span class="hljs-comment">// 100</span>

        a1.a = <span class="hljs-number">10</span>;
        abc(a1.a);
        System.out.println(a1.a); <span class="hljs-comment">// 10</span>
    }

    <span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">changeA</span><span class="hljs-params">(A a1)</span> {
        a1.a = <span class="hljs-number">100</span>;
    }

    <span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">abc</span><span class="hljs-params">(<span class="hljs-type">int</span> a)</span> {
        a = <span class="hljs-number">100</span>;
    }
}
<span class="hljs-keyword">class</span> <span class="hljs-title class_">A</span> {
    <span class="hljs-type">int</span> a;
}
</code></div></pre>
<h1><a id="2___53"></a>2. 面向对象语言特点： 封装，继承，多态</h1>
<h2><a id="21_gettersetter_55"></a>2.1 封装：属性私有化，通过getter和setter进行访问。</h2>
<h2><a id="22___57"></a>2.2 继承： 子类继承父类，获取父类的属性和方法</h2>
<ul>
<li>单继承多实现</li>
</ul>
<pre><div class="hljs"><code class="lang-Java"><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">Dog</span> <span class="hljs-keyword">extends</span> <span class="hljs-title class_">Animal</span> {
}
<span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">Animal</span> {
    String type;
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">move</span><span class="hljs-params">()</span> {
        System.out.println(<span class="hljs-string">&quot;Animal@move&quot;</span>);
    }

    <span class="hljs-keyword">public</span> String <span class="hljs-title function_">getType</span><span class="hljs-params">()</span> {
        <span class="hljs-keyword">return</span> type;
    }

    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">setType</span><span class="hljs-params">(String type)</span> {
        <span class="hljs-built_in">this</span>.type = type;
    }
}
</code></div></pre>
<pre><div class="hljs"><code class="lang-java">    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">main</span><span class="hljs-params">(String[] args)</span> {
        <span class="hljs-type">Animal</span> <span class="hljs-variable">a1</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">Animal</span>();
        a1.type = <span class="hljs-string">&quot;动物&quot;</span>;
        a1.move();

        <span class="hljs-type">Dog</span> <span class="hljs-variable">a2</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">Dog</span>();
        a2.type = <span class="hljs-string">&quot;狗&quot;</span>; <span class="hljs-comment">// 继承了父类的属性</span>
        a2.move(); <span class="hljs-comment">// 继承父类的行为</span>
    }
</code></div></pre>
<h2><a id="23__92"></a>2.3 多态：</h2>
<h3><a id="_94"></a>语义理解：一种事务多种形态。</h3>
<blockquote>
<p>​	美女抱着猫逛街。  &lt;一种事务&gt;</p>
<p>​    美女抱着英短逛街。&lt;多种形态&gt;</p>
<p>​    美女抱着橘猫逛街。&lt;多种形态&gt;</p>
</blockquote>
<pre><div class="hljs"><code class="lang-java">    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">main</span><span class="hljs-params">(String[] args)</span> {
        <span class="hljs-type">YingDuanCat</span> <span class="hljs-variable">yd</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">YingDuanCat</span>();
        <span class="hljs-type">JuCat</span> <span class="hljs-variable">jc</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">JuCat</span>();
        <span class="hljs-type">Meinv</span> <span class="hljs-variable">mm</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">Meinv</span>();

        <span class="hljs-comment">// 美女抱猫</span>
        <span class="hljs-comment">// 定义的时候是 父类类型， 真是对象是子类对象</span>
        mm.baoCat(yd);
        mm.baoCat(jc);
    }

<span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">Cat</span> {
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">jiao</span><span class="hljs-params">()</span> {
        System.out.println(<span class="hljs-string">&quot;--Cat@jiao---&quot;</span>);
    }
}
<span class="hljs-keyword">class</span> <span class="hljs-title class_">JuCat</span> <span class="hljs-keyword">extends</span> <span class="hljs-title class_">Cat</span> {

}
<span class="hljs-keyword">class</span> <span class="hljs-title class_">YingDuanCat</span> <span class="hljs-keyword">extends</span> <span class="hljs-title class_">Cat</span> {

}
<span class="hljs-keyword">class</span> <span class="hljs-title class_">Meinv</span> {
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">baoCat</span><span class="hljs-params">(Cat cat)</span> {
        cat.jiao();
    }
}
</code></div></pre>
<h3><a id="_132"></a>代码理解：</h3>
<ul>
<li>子类继承父类，覆盖父类方法。</li>
<li>定义父类类型变量，真实对象是子类对象。调用方法调用的是真是对象的方法</li>
</ul>
<pre><div class="hljs"><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">main</span><span class="hljs-params">(String[] args)</span> {
    <span class="hljs-type">Cat</span> <span class="hljs-variable">c1</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">JuCat</span>();
    <span class="hljs-comment">// 调用的是橘猫的 叫</span>
    c1.jiao();

    <span class="hljs-type">Cat</span> <span class="hljs-variable">c2</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">YingDuanCat</span>();
    <span class="hljs-comment">// 调用的是英短猫的 叫</span>
    c2.jiao();
}

<span class="hljs-keyword">class</span> <span class="hljs-title class_">JuCat</span> <span class="hljs-keyword">extends</span> <span class="hljs-title class_">Cat</span> {
    <span class="hljs-meta">@Override</span>
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">jiao</span><span class="hljs-params">()</span> {
        System.out.println(<span class="hljs-string">&quot;---橘猫叫声很大-------&quot;</span>);
    }
}
<span class="hljs-keyword">class</span> <span class="hljs-title class_">YingDuanCat</span> <span class="hljs-keyword">extends</span> <span class="hljs-title class_">Cat</span> {
    <span class="hljs-meta">@Override</span>
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">jiao</span><span class="hljs-params">()</span> {
        System.out.println(<span class="hljs-string">&quot;---英短叫声很小-------&quot;</span>);
    }
}

</code></div></pre>
<h1><a id="3__163"></a>3. 包装类：</h1>
<p>8个包装类对应8个基本类型。</p>
<ul>
<li>Integer 对应 int型； 在编译时自动拆箱</li>
</ul>
<pre><div class="hljs"><code class="lang-java">        <span class="hljs-comment">// 编译时 隐式转换（自动装箱拆箱）</span>
        <span class="hljs-type">Integer</span> <span class="hljs-variable">a2</span> <span class="hljs-operator">=</span> <span class="hljs-number">10</span>;
        <span class="hljs-type">int</span> <span class="hljs-variable">a3</span> <span class="hljs-operator">=</span> a2;

        <span class="hljs-comment">// 字符串与基本类型转换</span>
        <span class="hljs-type">int</span> <span class="hljs-variable">a4</span> <span class="hljs-operator">=</span> Integer.parseInt(<span class="hljs-string">&quot;123&quot;</span>);
        System.out.println(a4);
        <span class="hljs-comment">// 获取 10的 二进制</span>
        System.out.println(Integer.toBinaryString(a3));
        System.out.println(Integer.toHexString(a3));
</code></div></pre>
<table>
<thead>
<tr>
<th>类型</th>
<th>包装类型</th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td>byte</td>
<td>Byte</td>
<td></td>
</tr>
<tr>
<td>short</td>
<td>Short</td>
<td></td>
</tr>
<tr>
<td>int</td>
<td>Integer</td>
<td></td>
</tr>
<tr>
<td>long</td>
<td>Long</td>
<td></td>
</tr>
<tr>
<td>float</td>
<td>Float</td>
<td></td>
</tr>
<tr>
<td>double</td>
<td>Double</td>
<td></td>
</tr>
<tr>
<td>boolean</td>
<td>Boolean</td>
<td></td>
</tr>
<tr>
<td>char</td>
<td>Character</td>
<td></td>
</tr>
</tbody>
</table>
<h1><a id="4__195"></a>4. 抽象类：</h1>
<ol>
<li>没有方法体的方法是抽象方法，用abstract修饰</li>
<li>含有抽象方法的类位抽象类型，用abstract修饰</li>
<li>抽象类可以含有非抽象方法，也可以没有抽象方法</li>
<li>子类继承抽象类，要覆盖所有的抽象方法。</li>
<li>抽象类不能实例化</li>
</ol>
<pre><div class="hljs"><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">TestMain7</span> {
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">main</span><span class="hljs-params">(String[] args)</span> {
<span class="hljs-comment">//        B b = new B(); 不能实例化</span>
        <span class="hljs-type">B</span> <span class="hljs-variable">b</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">B1</span>();
    }
}
<span class="hljs-keyword">abstract</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">B</span> {
    <span class="hljs-comment">// 抽象方法</span>
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">abstract</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">b</span><span class="hljs-params">()</span>;
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">c</span><span class="hljs-params">()</span> {

    }
}
<span class="hljs-keyword">class</span> <span class="hljs-title class_">B1</span> <span class="hljs-keyword">extends</span> <span class="hljs-title class_">B</span> {
    <span class="hljs-meta">@Override</span>
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">b</span><span class="hljs-params">()</span> { <span class="hljs-comment">// 必须覆盖抽象方法</span>
    }
}


</code></div></pre>
<h1><a id="5_interface_226"></a>5. 接口：interface</h1>
<ol>
<li>接口中的方法都是抽象方法，强制默认修饰 <code>public abstract</code></li>
<li>接口中的属性都是 常量：    强制默认修饰： <code>public static fianl</code></li>
<li>子类 实现 接口 必须 覆盖所有方法。</li>
<li>接口不能实例化。</li>
<li>java是单继承多实现的，  接口可以多继承</li>
</ol>
<pre><div class="hljs"><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">TestMain8</span> {
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">main</span><span class="hljs-params">(String[] args)</span> {
<span class="hljs-comment">//        D.name = &quot;aaa&quot;; // 常量修改不了值</span>
    }
}
<span class="hljs-keyword">interface</span> <span class="hljs-title class_">D</span> {
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">final</span> <span class="hljs-type">String</span> <span class="hljs-variable">name</span> <span class="hljs-operator">=</span> <span class="hljs-string">&quot;hello world&quot;</span>;
    <span class="hljs-keyword">void</span> <span class="hljs-title function_">a</span><span class="hljs-params">()</span>; <span class="hljs-comment">// 默认 public abstract</span>
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">b</span><span class="hljs-params">()</span>; <span class="hljs-comment">// private 修饰报错，强制默认</span>
}
<span class="hljs-keyword">class</span> <span class="hljs-title class_">E</span> <span class="hljs-keyword">implements</span> <span class="hljs-title class_">D</span> {
    <span class="hljs-meta">@Override</span>
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">a</span><span class="hljs-params">()</span> {}
    <span class="hljs-meta">@Override</span>
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">b</span><span class="hljs-params">()</span> {}
}
<span class="hljs-keyword">interface</span> <span class="hljs-title class_">F</span> <span class="hljs-keyword">extends</span> <span class="hljs-title class_">D</span>, Serializable, Closeable, Comparable {

}
</code></div></pre>
<h1><a id="6__256"></a>6. 单继承多实现</h1>
<pre><div class="hljs"><code class="lang-java">Class A extens B <span class="hljs-keyword">implements</span> <span class="hljs-title class_">C</span>,D {  }
</code></div></pre>
<p>抽象类用于主体上的关系： 例如： 狗是动物，  动物可以是抽象类</p>
<p>接口用于功能性，描述性的多数以able结尾：  例如：  鸟  是动物（抽象类）， 能飞（接口）</p>
<h1><a id="7__268"></a>7. 权限访问修饰符</h1>
<table>
<thead>
<tr>
<th>修饰符</th>
<th>当前类中</th>
<th>当前包中</th>
<th>跨包，继承</th>
<th>跨包</th>
</tr>
</thead>
<tbody>
<tr>
<td>private</td>
<td>√</td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>default|package</td>
<td>√</td>
<td>√</td>
<td></td>
<td></td>
</tr>
<tr>
<td>protected</td>
<td>√</td>
<td>√</td>
<td>√</td>
<td></td>
</tr>
<tr>
<td>public</td>
<td>√</td>
<td>√</td>
<td>√</td>
<td>√</td>
</tr>
</tbody>
</table>
<h1><a id="8__279"></a>8. 匿名内部类：</h1>
<blockquote>
<p>语法：</p>
<pre><div class="hljs"><code class="lang-java">父类  变量 = <span class="hljs-keyword">new</span>  父类() {
    <span class="hljs-comment">// 子类类体，可以写属性，方法。一般用于方法覆盖</span>
}
</code></div></pre>
</blockquote>
<pre><div class="hljs"><code class="lang-java"><span class="hljs-keyword">package</span> lesson02;

<span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">TestMain9</span> {
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">main</span><span class="hljs-params">(String[] args)</span> {

        <span class="hljs-type">Fa</span> <span class="hljs-variable">a1</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">Fa</span>();
        a1.aaa();

        <span class="hljs-type">Fa</span> <span class="hljs-variable">a2</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">Fa</span>() {
            <span class="hljs-comment">// 匿名类体</span>
            <span class="hljs-meta">@Override</span>
            <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">aaa</span><span class="hljs-params">()</span> {
                System.out.println(<span class="hljs-string">&quot;----匿名类@aaa()-------&quot;</span>);
            }
        };
        <span class="hljs-comment">// 多态， 调用的是覆盖的方法</span>
        a2.aaa();

    }
}
<span class="hljs-keyword">class</span> <span class="hljs-title class_">Fa</span> {
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">aaa</span><span class="hljs-params">()</span> {
        System.out.println(<span class="hljs-string">&quot;-----Fa@aaa()-----&quot;</span>);
    }
}
</code></div></pre>
<h1><a id="9__317"></a>9 异常处理机制：</h1>
<h2><a id="91__319"></a>9.1 分类</h2>
<ol>
<li>
<p>CheckedException； 编译时异常：  编译器提示我们处理。</p>
<ol>
<li>FileNotFoundException： 编译器提示我们去处理<img src="C:%5CUsers%5CThinkpad%5CAppData%5CRoaming%5CTypora%5Ctypora-user-images%5Cimage-20211229144722401.png" alt="image-20211229144722401" /></li>
</ol>
</li>
<li>
<p>RuntimeExcepiton:  运行时异常， 真的有这个类RuntimeException。</p>
<ol>
<li>这个就是你写错了，要自己解决的</li>
</ol>
</li>
</ol>
<table>
<thead>
<tr>
<th>异常名</th>
<th>解释</th>
<th>解释</th>
<th>处理方式</th>
</tr>
</thead>
<tbody>
<tr>
<td>ArithmeticException</td>
<td>算术异常</td>
<td>10/0</td>
<td>检查数学公式</td>
</tr>
<tr>
<td>NullPointerException</td>
<td>空指针异常</td>
<td>obj.XXX()</td>
<td>检查.前面的对象是否为空</td>
</tr>
<tr>
<td>ArrayIndexOutOfBoundsException<br />IndexOutOfBoundsException</td>
<td>数组下标越界异常<br />下标越界</td>
<td>int[] a1 = new int[2]; // {0, 0}<br />a1[2]</td>
<td>检查下标的值是否在范围</td>
</tr>
<tr>
<td>ClassCastException</td>
<td>类型转换异常</td>
<td>M a1 = new M1(); ;  M2 a3 = (M2) a1;</td>
<td>检查多态中真是对象是谁</td>
</tr>
<tr>
<td>NumberFormatException<br />IllegalArgumentException</td>
<td>严重的参数异常</td>
<td>System.getProperty(&quot;&quot;);<br />int a = Integer.parseInt(“ajflasjfla”);</td>
<td>检查参数是否正确</td>
</tr>
</tbody>
</table>
`}